package main

import (
	"fmt"
	"log"
	"math/rand"
	"net/http"
	"os"
	"time"
)

func IndexHandler(w http.ResponseWriter, r *http.Request) {
	//net.Dial("127.0.0.1",":8080")
	fmt.Println("accept conn")

	count := rand.Int() % 10
	fmt.Println("sleep ", count)
	time.Sleep(time.Duration(count) * time.Second)

	fmt.Fprintln(w, "hello world")
}
func main() {
	port := os.Args[1]
	http.HandleFunc("/", IndexHandler)
	server := &http.Server{
		Addr:           port,
		ReadTimeout:    30 * time.Second,
		WriteTimeout:   30 * time.Second,
		MaxHeaderBytes: 2 << 16,
	}

	log.Printf("[info] start http server listening %s", server.Addr)

	err := server.ListenAndServe()
	fmt.Println(err)
}
